﻿using System;
using System.Collections.Generic;
using RootMotion.FinalIK;
using UnityEngine;

// Token: 0x020002CE RID: 718
public class PoseIK
{
	// Token: 0x060010C7 RID: 4295 RVA: 0x0007AC08 File Offset: 0x00078E08
	public PoseIK(GiantessIK gtsIK, FullBodyBipedIK ik, LookAtIK lookAt, EntityBase entity)
	{
		this.ik = ik;
		this.headIk = lookAt;
		this.gtsik = gtsIK;
		this.entity = entity;
		this.effectors = new List<IKEffector>();
		this.bendgoals = new List<IKConstraintBend>();
		this.body = ik.solver.bodyEffector;
		this.effectors.Add(this.body);
		this.leftHand = ik.solver.leftHandEffector;
		this.effectors.Add(this.leftHand);
		this.rightHand = ik.solver.rightHandEffector;
		this.effectors.Add(this.rightHand);
		this.rightFoot = ik.solver.rightFootEffector;
		this.effectors.Add(this.rightFoot);
		this.leftFoot = ik.solver.leftFootEffector;
		this.effectors.Add(this.leftFoot);
		this.leftShoulder = ik.solver.leftShoulderEffector;
		this.effectors.Add(this.leftShoulder);
		this.rightShoulder = ik.solver.rightShoulderEffector;
		this.effectors.Add(this.rightShoulder);
		this.rightThight = ik.solver.rightThighEffector;
		this.effectors.Add(this.rightThight);
		this.leftThight = ik.solver.leftThighEffector;
		this.effectors.Add(this.leftThight);
		this.leftElbow = ik.solver.leftArmChain.bendConstraint;
		this.leftElbow.bendGoal = new GameObject("Bend Goal").transform;
		this.leftElbow.bendGoal.SetParent(entity.transform);
		this.bendgoals.Add(this.leftElbow);
		this.rightElbow = ik.solver.rightArmChain.bendConstraint;
		this.rightElbow.bendGoal = UnityEngine.Object.Instantiate<Transform>(this.leftElbow.bendGoal, entity.transform);
		this.bendgoals.Add(this.rightElbow);
		this.leftKnee = ik.solver.leftLegChain.bendConstraint;
		this.leftKnee.bendGoal = UnityEngine.Object.Instantiate<Transform>(this.leftElbow.bendGoal, entity.transform);
		this.bendgoals.Add(this.leftKnee);
		this.rightKnee = ik.solver.rightLegChain.bendConstraint;
		this.rightKnee.bendGoal = UnityEngine.Object.Instantiate<Transform>(this.leftElbow.bendGoal, entity.transform);
		this.bendgoals.Add(this.rightKnee);
		this.head = this.headIk.solver;
	}

	// Token: 0x060010C8 RID: 4296 RVA: 0x0007AEC4 File Offset: 0x000790C4
	public void ResetEffectors()
	{
		this.Reset();
	}

	// Token: 0x060010C9 RID: 4297 RVA: 0x0007AECC File Offset: 0x000790CC
	private void Reset()
	{
		foreach (IKEffector ikeffector in this.effectors)
		{
			ikeffector.position = ikeffector.bone.position;
			ikeffector.rotation = ikeffector.bone.rotation;
		}
		foreach (IKConstraintBend ikconstraintBend in this.bendgoals)
		{
			Vector3 b = (ikconstraintBend.bone1.position + ikconstraintBend.bone3.position) / 2f;
			Vector3 normalized = (ikconstraintBend.bone2.position - b).normalized;
			ikconstraintBend.bendGoal.position = ikconstraintBend.bone2.position + normalized * 200f * this.entity.Scale;
		}
		this.head.IKPosition = this.head.head.transform.position + this.head.head.transform.forward * 500f * this.entity.Scale;
		this.head.headWeight = 1f;
		this.head.eyesWeight = 1f;
		this.head.bodyWeight = 0f;
		this.head.clampWeight = 0f;
		this.head.clampWeightHead = 0f;
		this.head.clampWeightEyes = 0f;
		this.gtsik.EnableIK(true);
		this.SetWeight(1f);
	}

	// Token: 0x060010CA RID: 4298 RVA: 0x0007B0D0 File Offset: 0x000792D0
	public void SetWeight(float weight)
	{
		foreach (IKEffector ikeffector in this.effectors)
		{
			ikeffector.positionWeight = weight;
			ikeffector.rotationWeight = weight;
		}
		foreach (IKConstraintBend ikconstraintBend in this.bendgoals)
		{
			ikconstraintBend.weight = weight;
		}
		this.head.IKPositionWeight = weight;
		this.ik.solver.leftArmMapping.weight = weight;
		this.ik.solver.rightArmMapping.weight = weight;
		if (weight > 0f)
		{
			this.gtsik.EnableIK(true);
		}
		else
		{
			this.gtsik.EnableIK(false);
		}
	}

	// Token: 0x04001587 RID: 5511
	private GiantessIK gtsik;

	// Token: 0x04001588 RID: 5512
	private EntityBase entity;

	// Token: 0x04001589 RID: 5513
	private FullBodyBipedIK ik;

	// Token: 0x0400158A RID: 5514
	private LookAtIK headIk;

	// Token: 0x0400158B RID: 5515
	public IKSolverLookAt head;

	// Token: 0x0400158C RID: 5516
	public IKEffector body;

	// Token: 0x0400158D RID: 5517
	public IKEffector leftHand;

	// Token: 0x0400158E RID: 5518
	public IKEffector rightHand;

	// Token: 0x0400158F RID: 5519
	public IKEffector leftFoot;

	// Token: 0x04001590 RID: 5520
	public IKEffector rightFoot;

	// Token: 0x04001591 RID: 5521
	public IKEffector leftShoulder;

	// Token: 0x04001592 RID: 5522
	public IKEffector rightShoulder;

	// Token: 0x04001593 RID: 5523
	public IKEffector leftThight;

	// Token: 0x04001594 RID: 5524
	public IKEffector rightThight;

	// Token: 0x04001595 RID: 5525
	private List<IKEffector> effectors;

	// Token: 0x04001596 RID: 5526
	public IKConstraintBend leftElbow;

	// Token: 0x04001597 RID: 5527
	public IKConstraintBend rightElbow;

	// Token: 0x04001598 RID: 5528
	public IKConstraintBend leftKnee;

	// Token: 0x04001599 RID: 5529
	public IKConstraintBend rightKnee;

	// Token: 0x0400159A RID: 5530
	private List<IKConstraintBend> bendgoals;
}
